package com.pay.controller;

import com.alipay.api.demo.AliPayProvider;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tjq
 * @Title: AlipayController
 * @Description: 支付宝控制器
 * @date 2019/8/13 9:26
 */
@RestController
public class AliPayController extends AbstractAliPayApiController implements AliPayProvider {
    private Logger logger = LoggerFactory.getLogger(AliPayController.class);

    @Autowired
    private AliPayBean aliPayBean;

    @Override
    public AliPayApiConfig getApiConfig() {
        AliPayApiConfig aliPayApiConfig;
        try {
            aliPayApiConfig = AliPayApiConfigKit.getApiConfig(aliPayBean.getAppId());
        } catch (Exception e) {
            aliPayApiConfig = AliPayApiConfig.builder()
                    .setAppId(aliPayBean.getAppId())
                    .setAliPayPublicKey(aliPayBean.getPublicKey())
                    .setCharset("UTF-8")
                    .setPrivateKey(aliPayBean.getPrivateKey())
                    .setServiceUrl(aliPayBean.getServerUrl())
                    .setSignType("RSA2")
                    .build();
        }
        return aliPayApiConfig;
    }

    @Override
    public String desc() {
        return "欢迎使用 SpringCloud 中的支付宝支付 -By tjq  <br/><br>  QQ：244593643";
    }

    @Override
    public String aliPay() {
        AliPayApiConfig apiConfig = getApiConfig();
        logger.info("调用支付宝接口");
        return null;
    }


}
